<template>
  <view class="goodsDeliteItem">
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" indicator-color="#c00000"
      :circular="true" :display-multiple-items="1">
      <swiper-item v-for="(item,i) in detailsList.pics" :key="i" class="swiperwid" @click="imageBigList(i)">
        <img :src="item.pics_big_url"></img>
      </swiper-item>
      <swiper-item>
        <view class="swiper-item"></view>
      </swiper-item>
    </swiper>

    <view class="textBox">


      <view class="textPrice">
        <text v-if="detailsList.goods_price">¥{{detailsList.goods_price}}</text>
        <!-- <view>{{detailsList.goods_price}}</view> -->
      </view>

      <view class="textName">
        <view class="textSearch">{{detailsList.goods_name}}</view>
        <view class="texticon">
          <uni-icons type="star" size="30"></uni-icons>
          <text>收藏</text>
        </view>
      </view>
    </view>
    <view class="Courier">快递,免运费 ---{{cart.length}}</view>
    <rich-text :nodes="detailsList.goods_introduce"></rich-text>
    <!-- 会警告 -->
    <!--     <view class="" v-html="detailsList.goods_introduce"> </view> -->
    <uni-goods-nav class="buttomItem" :fill="true" open-type="contact" :options="options" :buttonGroup="buttonGroup"
      @click="onClick" @buttonClick="buttonClick" />
    <button open-type="contact" class="buttonItem">
      <view class="weixinItem">
        <uni-icons type="chatbubble" size="20"></uni-icons>
        <view class="text">客服</view>
      </view>
    </button>
  </view>

  </view>
</template>

<script>
  import {
    mapState,
    mapMutations,
    mapGetters
  } from "vuex"
  export default {
    computed: {
      ...mapState("m_cart", ["cart"]),
      ...mapGetters("m_cart", ["total"]),
    },
    watch: {
      // total(newval){
      // const findRues=this.options.find(item=>item.text==="购物车")
      //   if(findRues){
      //    findRues.info=newval
      //   }
      // }
      total: {
        handler(newval) {
          const findRues = this.options.find(item => item.text === "购物车")
          if (findRues) {
            findRues.info = newval
          }
             
        },
        immediate: true
      },
  
    },
    data() {
      return {
        detailsList: [],
        options: [{
            icon: '',
            text: '',

          }, {
            icon: 'shop',
            text: '店铺',
            info: 2,
            infoBackgroundColor: '#007aff',
            infoColor: "red"
          },
          {
            icon: 'cart',
            text: '购物车',
            info: 0
          }
        ],
        buttonGroup: [{
            text: '加入购物车',
            backgroundColor: '#ff0000',
            color: '#fff'
          },
          {
            text: '立即购买',
            backgroundColor: '#ffa200',
            color: '#fff'
          }
        ],

      };
    },
    onLoad(options) {
      const id = options.goods_id
      this.getDetailsList(id)
    },
    methods: {
      ...mapMutations("m_cart", ["getAddCart"]),
      onClick(e) {
        console.log(e.content.text)
        if (e.content.text === "客服") {
          console.log("123")
          // openType="contact"
        }

        if (e.content.text === "购物车") {
          uni.switchTab({
            url: "/pages/cart/cart"
          })
        }





        uni.showToast({
          title: `点击${e.content.text}`,
          icon: 'none',

        })
      },
      buttonClick(e) {
        if (e.content.text === "加入购物车") {
          const goods = {
            goods_id: this.detailsList.goods_id,
            goods_count: 1,
            goods_name: this.detailsList.goods_name,
            goods_price: this.detailsList.goods_price,
            goods_big_logo: this.detailsList.goods_big_logo,
            goods_state: true
          }
          this.getAddCart(goods)
        }

        // console.log(e)
        // this.options[2].info++

      },
      imageBigList(i) {
        uni.previewImage({
          current: i,
          urls: this.detailsList.pics.map(x => x.pics_big)
        })
      },
      async getDetailsList(id) {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/goods/detail', {
          goods_id: id
        })
        if (res.meta.status !== 200) return uni.$showmag("数据获取失败", 1000, "none")
        res.message.goods_introduce = res.message.goods_introduce.replace(/<img/g, "<img style='display:block;'")
          .replace(/.webp/g, ".jpg")

        this.detailsList = res.message
        console.log(this.detailsList.goods_price)
      }
    },
  }
</script>

<style lang="scss">
  swiper {

    height: 370px;

    image {
      height: 100%;
      width: 100%;
    }
  }

  .textBox {
    margin: 10px;

    .textPrice {
      font-size: 20px;
      font-weight: bold;
      color: red;

    }

    .textName {
      width: 300px;
      display: flex;
      border-right: 1px solid #E5E5E5;
      position: relative;

      .textSearch {
        width: 280px;
        font-size: 13px;
      }

      .texticon {
        display: flex;
        flex-direction: column;
        position: absolute;
        right: -45px;
        color: #aaaaa3;
      }
    }

  }

  .Courier {
    margin: 10px;
    font-size: 12px;
    color: #a8a8a8;
    ;
  }

  button::after {
    border: none;
  }

  .buttomItem {
    width: 375px;
    position: fixed;
    bottom: 0;
    z-index: 999;
    background: white;

  }

  .goodsDeliteItem {
    padding-bottom: 50px;
  }

  .weixinItem {

    display: flex;
    flex-direction: column;
    margin-bottom: -10px;

    uni-icons {

      position: fixed;
      bottom: 9px;
      left: 17px;

    }

    .text {
      position: fixed;
      bottom: -1px;
      left: 13px;
      font-size: 12px;
      color: #6A6A6A
    }
  }

  .buttonItem {
    height: 50px;
    width: 50px;
    position: fixed;
    z-index: 1500;
    left: -1;
    bottom: 0;
    background: #fff;

  }
</style>
